package com.scau.service.impl;

import com.scau.common.exception.BusinessException;
import com.scau.dao.ClassScheduleDao;
import com.scau.dao.LectureRecordDao;
import com.scau.dao.StudentDao;
import com.scau.entity.ClassSchedule;
import com.scau.entity.LectureRecord;
import com.scau.entity.Student;
import com.scau.service.ClassScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class ClassScheduleServiceImpl implements ClassScheduleService {

    @Autowired
    private ClassScheduleDao classScheduleDao;

    @Autowired
    private StudentDao studentDao;

    @Autowired
    private LectureRecordDao lectureRecordDao;

    @Override
    public void addAll(List<ClassSchedule> classSchedules) {
        classScheduleDao.deleteAll();
        classScheduleDao.save(classSchedules);
    }

    @Override
    public Page<ClassSchedule> findAll(ClassSchedule classSchedule, Pageable pageable) {
        return classScheduleDao.findAll(Example.of(classSchedule), pageable);
    }

    @Override
    public ClassSchedule findOne(Long classScheduleId) {
        ClassSchedule classSchedule = classScheduleDao.findOne(classScheduleId);

        if (classSchedule == null) {
            throw new BusinessException("不存在该课程");
        }
        return classSchedule;
    }

    @Transactional
    @Override
    public void finishedClass() {


    }
}
